#include "Pacs_ShowCheckPart.h"
#include "DBOperate.h"
#include <QMouseEvent>
#include <QItemDelegate>

Pacs_ShowCheckPart::Pacs_ShowCheckPart(QWidget *parent)
	: QWidget(parent)
{
	this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint /*| Qt::WindowStaysOnTopHint*/);
	this->setWindowModality(Qt::ApplicationModal);
	ui.setupUi(this);
	onInitListWidget();
}
void Pacs_ShowCheckPart::onInitListWidget()
{
	QList<CheckPart> listChaekPart = DBOperate::GetKernel()->getShowCheckPart();
	if (listChaekPart.length() > 0) {
		for (int i = 0; i < listChaekPart.length(); ++i)
		{
			CheckPart partInfo = listChaekPart[i];
			QListWidgetItem *item = new QListWidgetItem;
			item->setCheckState(Qt::Unchecked);
			item->setText(partInfo.strPartName);
			item->setData(Qt::UserRole+2,QVariant::fromValue(partInfo));
			ui.listWidget->addItem(item);
		}
	}
}

void Pacs_ShowCheckPart::on_btnClose_clicked()
{
	this->hide();
	ui.listWidget->clear();
}

void Pacs_ShowCheckPart::onShowWidget()
{
	ui.listWidget->clear();
	onInitListWidget();
	this->show();
}

void Pacs_ShowCheckPart::on_btnOK_clicked()
{
	QStringList strList;
	for (int i = 0; i < ui.listWidget->count(); ++i)
	{
		QListWidgetItem *item = ui.listWidget->item(i);
		if (item->checkState() == Qt::Checked)
		{
			QString text = item->text();
			strList.append(text);
		}
	
	}
	if (strList.length() > 0) 
	{
		emit newString(strList);
	}
	on_btnClose_clicked();
	
}
void Pacs_ShowCheckPart::on_btnCancel_clicked()
{
	on_btnClose_clicked();
}
void Pacs_ShowCheckPart::on_btnEdit_clicked()
{

}
void Pacs_ShowCheckPart::mousePressEvent(QMouseEvent *e)
{
	if (e->button() == Qt::LeftButton)
	{
		m_Drag = true;
		lastPoint = e->globalPos();
		
	}

}

void Pacs_ShowCheckPart::mouseReleaseEvent(QMouseEvent *)
{
	m_Drag = false;
}
void Pacs_ShowCheckPart::mouseMoveEvent(QMouseEvent *e)
{
	if (m_Drag && e->buttons() == Qt::LeftButton)
	{
		this->move(this->pos() + e->globalPos() - lastPoint);
		lastPoint = e->globalPos();
	}
}
Pacs_ShowCheckPart::~Pacs_ShowCheckPart()
{

}
